#include <vector>
#include <iostream>
using namespace std;

int MaxSubSumOfSequence(const vector<int> & a){
	int maxSum = 0;
	int nowSum = 0;
	
	
    for(int j = 0; j < a.size(); j++)
    {
    	nowSum += a[j];
    	
    	
    	if (nowSum > maxSum)
    	    maxSum = nowSum;
    	else if(nowSum < 0)
    	    nowSum = 0;
	}
	
	return maxSum;
}

int main(){
	vector<int> b = {1 , -2 , 3 , 5 , -1} ;
	cout << MaxSubSumOfSequence(b) << endl;
	return 0;
}
